class Settings {
    constructor(root) {
        this.root = root;
        this.platform = "web";
        this.username = "";
        this.photo = "";

        this.$settings = $(`
<div class="game-settings">
    <div class="game-settings-login">
        <div class="game-settings-title">
            登录
        </div>
        <div class="game-settings-username">
            <div class="game-settings-item">
                <input type="text" placeholder="用户名">
            </div>
        </div>
    </div>

    <div class="game-settings-register"> 
    </div>
</div>
        `);

        this.$login = this.$settings.find(".game-settings-login");
        this.$login.hide();
        this.$register = this.$settings.find(".game-settings-register");
        this.$register.hide();

        this.root.$ac_game.append(this.$settings);
        this.start();
    }

    start() {
        this.getinfo();
    }

    register() {
        this.$login.hide();
        this.$register.show();
    }

    login() {
        this.$register.hide();
        this.$login.show();
    }

    getinfo() {
        let outer = this;
        $.ajax({
            url: "http://8.134.12.212:8000/settings/getinfo/",
            type: "GET",
            data: {
                platform: outer.platform,
            },
            success: function (resp) {
                console.log(resp)
                if (resp.result === "success") {
                    outer.username = resp.username;
                    outer.photo = resp.photo;
                    outer.hide();
                    outer.root.menu.show();
                } else {
                    outer.login();
                }
            }
        });
    }

    hide() {
        this.$settings.hide();
    }

    show() {
        this.$settings.show();
    }
}